package org.monster.context.core.file;

import org.monster.context.core.WebAppsFile;

import java.io.File;

/**
 * 文件安排任务
 *
 * @author Monster
 */
public class FileSchedulerTask implements Runnable {

    private WebAppsFile webAppsFile;
    private boolean firstRun = true;
    private File file = null;
    private FileCatalog catalog;
    private FileSet set;
    private FileInvoker invoker;

    /**
     * 构造方法
     *
     * @param file        文件
     * @param webAppsFile 网应用文件
     * @param set         文件集合
     * @param catalog     目录
     */
    public FileSchedulerTask(File file, WebAppsFile webAppsFile,
                             FileSet set, FileInvoker invoker, FileCatalog catalog) {
        this.file = file;
        this.webAppsFile = webAppsFile;
        this.set = set;
        this.invoker = invoker;
        this.catalog = catalog;
    }

    /**
     * 运行
     */
    @Override
    public void run() {
        if (firstRun && file != null) {
            firstRun = false;
            webAppsFile.recFile(file);
        } else {
            invoker.execute(file, set, catalog);
            set.clear();
        }
    }
}
